

var size=10;
$(document).ready(function(){
	getDataList(1);
});

    
	function getDataList(current) {
		//获取信息列表
		$("#thislist").html("");
		$.ajax({
			url: urlcore + "/api/msgModel/selectPage?current=" + current + "&size=" + size,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					//i表示在data中的索引位置，n表示包含的信息的对象
					$.each(data.data.records, function(i, n) {
						var id = n.id;
						var str=getType(n.type);
						var thislist =
							'<tr class="footable-even" style="display: table-row;">' +
							'<td class="footable-visible"><input type="checkbox" onclick="arrayAdd(this)" id="' + n.id + '"/></td>' +
							'		<td>' + id + '</td>' +
							'		<td>' + str+ '</td>' +
							'		<td>' + n.title + '</td>' +
							'		<td>' + n.content + '</td>' +
							'		<td>' + n.gmtDatetime + '</td>' +
							'		<td>' +
							'           <a class=""  name="修改" href="msg_model_add.html?id=' + id + '"> 修改</a>' + '&nbsp' +
							'           <a class=""  name="删除" href="javascript:;" onclick="deleteeach(' + n.id + ')">删除</a>'  +
							'		</td>' +
							'	</tr>';
						$('#thislist').append(thislist);
					});
				
					$("#pager").pager({
						pagenumber:current,
						pagecount: data.data.pages,
						totalcount: data.data.total,
						buttonClickCallback: PageClick
					});


				} else {
					if(data.msg != '空数据') {
						alert(data.msg)
					} else {
						$('#thiscount').text(0);
					}
				}

			}
			
		});
	}
	//回调函数  
	PageClick = function(pageclickednumber) {
		init(pageclickednumber);
	}



/**
 * 删除
 * @param {Object} id
 */
function deleteeach(id) {
	if(confirm("您确定删除这条信息吗？")){
	$.ajax({
		url: urlcore + "/api/msgModel/deleteOne?id=" + id,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				location.reload();
			} else {
				alert(data.msg);
			}
		}
	});
  }
}

/**
 * 获取消息类型
 * @param {Object} type
 */

function getType(type){
	var str="";
	if(type==1){
		str="协议"
	}else if(type==2){
		str="推送消息"
	}
	return str;
}
